The present invention relates generally to computer systems, and more specifically, to runtime management of table of contents (TOC) pointer save and restore commands.
In computer software, an application binary interface (ABI) describes the low-level interface between an application program and the operating system or between the application program and another application. The ABI cover details such as data type, size, and alignment; the calling conventions which controls how function arguments are passed and how return values are retrieved; the system call numbers and how an application should make system calls to the operating system; and in the case of a complete operating system ABI, the binary format of object files, program libraries and so on. Several ABIs (e.g., the Interactive Unix ABI allowing to a wide range of programs to run on a variety of Unix and Linux variants for the Intel x86 architecture) allow an application program from one operating system (OS) supporting that ABI to run without modifications on any other such system, provided that necessary shared library code are present, and similar prerequisites are fulfilled.
The program development cycle of a typical application program includes writing source code, compiling the source code into object files, building shared library code, and linking of the object files into a main executable program. Additional preparation, including loading of the main executable program, and loading of the shared library code for application start-up occurs before the application is executed on a particular hardware platform.
The compiler works on a single source file (compile unit) at a time to generate object files. The compiler generates object code without knowing the final address or displacement of the code/data. Specifically, the compiler generates object code that will access a TOC for variable values without knowing the final size of the TOC or offsets/addresses of various data sections. Placeholders for this information is left in the object code and updated by the linker A TOC is a variable address reference table that is utilized, for example in an AIX environment, to access program variables in a manner that supports shared library code and is data location independent. A similar structure, referred to as a global offset table (GOT), performs a similar function (e.g., indirect and dynamically relocatable access to variables) in a LINUX environment. One difference between a TOC and a GOT is that a TOC may contain actual data, where a GOT only contains addresses (pointers) to data. In the Linux PowerPC 64-bit environment the TOC contains the GOT section plus small data variables.
Each module in a computer program may have a different TOC pointer value. The TOC pointer register or GOT pointer register (referred to hereinafter as the TOC pointer register) is therefore saved and restored for each function call, either by the caller using one of inline code in the calling function and/or a procedure linkage table (PLT) stub code segment containing a TOC store, or by the callee function in conventions where the TOC pointer register is been treated as a preserved (i.e., callee-saved) register.